package com.tengju.payment.domain.model.transfer;

import com.tengju.payment.domain.model.TradeStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 转账状态
 *
 * @author 大木
 * @date: 2021/12/6 9:17 下午
 */
@Getter
@AllArgsConstructor
public enum PingAnTransferStatus {

    WAIT_PROCESS(0,"待处理"),
    HAD_TRANSFER(1,"已转账"),
    HAD_PAYMENT(2,"已打款"),
    REFUND_TICKET(3,"退票"),
    FAILED_TRANSFER(-1,"转账失败"),
    FAILED_CHARGE(-2,"打款失败"),
    ;

    Integer val;
    String desc;

    public static PingAnTransferStatus of(Integer code) {
        if (code == null) {
            return null;
        }

        for (PingAnTransferStatus type : values()) {
            if (type.val.equals(code)) {
                return type;
            }
        }
        return null;
    }

    public TradeStatus getTradeStatus(){
        if (this == WAIT_PROCESS || this == HAD_TRANSFER){
            return TradeStatus.PROCESS;
        } else if (this == HAD_PAYMENT){
            return TradeStatus.SUCCESS;
        } else if (this == REFUND_TICKET){
            return TradeStatus.DISHONOUR;
        } else {
            return TradeStatus.FAIL;
        }
    }
}
